package org.custom.spring.boot.security.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.custom.spring.boot.security.constant.SecurityConstant;
import org.springframework.security.core.GrantedAuthority;

/**
 * 系统角色相关实体类
 *
 * @author LiKun
 * @date 2021/11/8 18:55
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("system_role")
@ApiModel("系统角色实体类")
public class SystemRole implements GrantedAuthority {
    @TableId
    @ApiModelProperty(value = "id", notes = "角色ID")
    private String id;

    @ApiModelProperty(value = "name", notes = "角色名称")
    private String name;

    @ApiModelProperty(value = "enabled", notes = "角色是否可用")
    private boolean enabled;

    public SystemRole(String name) {
        this.name = name;
        this.enabled = true;
    }

    public SystemRole(String id, String name) {
        this.id = id;
        this.name = name;
        this.enabled = true;
    }

    /**
     * 获取匿名角色信息
     *
     * @return 匿名角色
     */
    public static final SystemRole getAnonymous() {
        return new SystemRole(SecurityConstant.ANONYMOUS);
    }

    @Override
    public String getAuthority() {
        return this.name;
    }
}
